You can also embed plots, for example:
Når rejetion af Silica plottes mod pH opnås linear regression med udtrykket silica rejection = 38.183 * pH - 335.39 Det antages derved at rejection af silica er baseret på hvilken fraktion der er ladet, hvilket er afhængigt af pH. SiO2_ladet er dermed = (38.183 * pH - 335.39)/100* [SiO2]
skal vi skelne mellem Steady state og batch?
## `geom_smooth()` using formula 'y ~ x'
Anion fraktion udregneds udfra Cl/[SO4]+[SiO2_ladet]+[Cl]
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
fit_Clrej_test1 = lm(Rej_Cl~Cl_anion, data = Ion_data_frame)
ggplotRegression(fit_Clrej_test1)
## `geom_smooth()` using formula 'y ~ x'
plot(x=predict(fit_Clrej_test1), y=na.omit(Ion_data_frame$Rej_Cl),
xlab='Predicted Values',
ylab='Actual Values',
main='Predicted vs. Actual Values',
abline(a=0, b=1))
fit2 = lm(Rej_Cl~Cl_anion, data = Ion_data_frame%>%filter(state=="Steady State"))
#pred.int <- predict(model, interval = "prediction")
ggplotly(ggplot(Ion_data_frame, aes(x=SO4_mmol, y=Rej_Cl,color=name))+geom_point())
ggplotRegression(fit_Clrej_test1)
## `geom_smooth()` using formula 'y ~ x'
ggplotly(ggplot(Ion_data_frame%>%filter(type %in% c("M_9.2","M_10","M_10.5")), aes(x=Recovery, y=Rej_SiO2,color=type))+geom_point()+geom_line())
multisalt = Ion_data_frame%>%filter(type %in% c("M_9.2","M_10","M_10.5"))
multisalt_rej = multisalt%>%gather(key,value, Rej_Na,Rej_Cl,Rej_Ca,Rej_SO4,Rej_SiO2)
multisalt_conc = multisalt%>%gather(key,value, Na_mmol,Cl_mmol,Ca_mmol,SO4_mmol,SiO2_mmol)
##### Model
ggplotRegression <- function (fit) {
require(ggplot2)
ggplot(fit$model, aes_string(x = names(fit$model)[2], y = names(fit$model)[1])) +
geom_point() +
stat_smooth(method = "lm", col = "red") +
labs(title = paste("Adj R2 = ",signif(summary(fit)$adj.r.squared, 5),
"Intercept =",signif(fit$coef[[1]],5 ),
" Slope =",signif(fit$coef[[2]], 5),
" P =",signif(summary(fit)$coef[2,4], 5)))
}
#
fit_SiO2_pH = lm(Rej_SiO2~SiO2_ladet+pH, data = multisalt%>%filter(type %in% c("M_10","M_10.5")))
ggplotRegression(fit_SiO2_pH)
## `geom_smooth()` using formula 'y ~ x'
summary(fit_SiO2_pH)
##
## Call:
## lm(formula = Rej_SiO2 ~ SiO2_ladet + pH, data = multisalt %>%
## filter(type %in% c("M_10", "M_10.5")))
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.0035 -1.2258 0.2272 1.2678 2.3037
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -347.675 40.962 -8.488 1.38e-05 ***
## SiO2_ladet 6.375 3.942 1.617 0.14
## pH 39.019 4.123 9.463 5.65e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.918 on 9 degrees of freedom
## Multiple R-squared: 0.9627, Adjusted R-squared: 0.9545
## F-statistic: 116.3 on 2 and 9 DF, p-value: 3.72e-07
#plot(x=predict(fit_SiO2_pH), y=na.omit(Ion_data_frame$Rej_SiO2),
# xlab='Predicted Values',
# ylab='Actual Values',
# main='Predicted vs. Actual Values',
# abline(a=0, b=1))
#plot(fit_SiO2_pH$residuals, pch = 16, col = "red")
#plot(cooks.distance(fit_SiO2_pH), pch = 16, col = "red")
multisalt_plot = multisalt_rej
rej_9.2=ggplot(multisalt_plot%>%filter(type=="M_9.2"), aes(x=Recovery, y=value,color= key))+geom_point()+geom_line()+geom_hline(yintercept=0)+
scale_color_brewer(palette= "Set1")+
labs(x="Water Recovery %",y="Rejection %", color="")+xlim(c(20,90))+ylim(c(-60,100))+
ggtitle("ID:1 - pH 9.2")
rej_10=ggplot(multisalt_plot%>%filter(type=="M_10"), aes(x=Recovery, y=value,color= key))+geom_point()+geom_line()+geom_hline(yintercept=0)+
scale_color_brewer(palette= "Set1")+
labs(x="Water Recovery %",y="Rejection %", color="")+xlim(c(20,90))+ylim(c(-60,100))+
ggtitle("ID:2 - pH 10")
rej_10.5=ggplot(multisalt_plot%>%filter(type=="M_10.5"), aes(x=Recovery, y=value,color= key))+geom_point()+geom_line()+geom_hline(yintercept=0)+
scale_color_brewer(palette= "Set1")+
labs(x="Water Recovery %",y="Rejection % ", color="")+xlim(c(20,90))+ylim(c(-60,100))+
ggtitle("ID:3 - pH 10.5")
ggarrange(rej_9.2,rej_10,rej_10.5, ncol=3, nrow=1, common.legend = TRUE, legend="bottom")#,align = "v")
rej_9.2=ggplotly(rej_9.2)
rej_10=ggplotly(rej_10)
rej_10.5=ggplotly(rej_10.5)
hejmeddig = subplot(rej_9.2,rej_10,rej_10.5,nrows=1)
hejmeddig
ggplotly(ggplot(Ion_data_frame%>%filter(type %in% c("ICR")), aes(x=Recovery, y=pH,color=type))+geom_point()+geom_line())
ICR = Ion_data_frame%>%filter(type %in% c("ICR"))
ICR_rej = ICR%>%gather(key,value, Rej_Na,Rej_Cl,Rej_Ca,Rej_SO4,Rej_SiO2)
rej_ICR=ggplot(ICR_rej, aes(x=Recovery, y=value,color= key))+geom_point()+geom_line()+geom_hline(yintercept=0)+
scale_color_brewer(palette= "Set1")+
labs(x="Water Recovery",y="Rejection", color="")+xlim(c(0,80))+ylim(c(-65,100))+
ggtitle("ICR")
ggplotly(rej_ICR)
ICR_conc = ICR%>%gather(key,value, Na_mmol,Cl_mmol,Ca_mmol,SO4_mmol,SiO2_mmol)
conc_ICR=ggplot(ICR_conc, aes(x=Recovery, y=value,color= key))+geom_point()+geom_line()+geom_hline(yintercept=0)+
scale_color_brewer(palette= "Set1")+
labs(x="Water Recovery",y="Feed Concentration", color="")+xlim(c(0,80))+ylim(c(0,NA))+
ggtitle("ICR")
ggplotly(conc_ICR)